package cn.tedu.boot041.controller;

import cn.tedu.boot041.entity.User;
import cn.tedu.boot041.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {
    @Autowired
    UserMapper mapper;
    @RequestMapping("/reg")
    public String reg(User user){
        System.out.println("user = " + user);
        User u=mapper.selectByUsername(user.getUsername());
        if(u!=null){
            return "用户名已存在";

        }
        mapper.insert(user);
        return "注册成功!";

    }
    @RequestMapping("/login")
    public String login(User user){
        User u=mapper.selectByUsername(user.getUsername());
        if(u!=null){
            if(user.getPassword().equals(u.getPassword())){
                return "登录成功";
            }
            return "密码错误";
        }
        return "用户名不存在";

    }@RequestMapping("/check")
    public  String check(String username){
        System.out.println("username = " + username);
        User u=mapper.selectByUsername(username);
        return u==null?"用户名可用!":"用户名已存在!";

    }

}
